import type { Module, ActionContext } from 'vuex'
import type { AxiosResponse } from 'axios'
import type { loopMonitoringBoxState } from './typings'
import {
  getLoopConfigureColors,
  getLoopMonitoringBoxList,
  getPowerDistributionFacilityCircuit,
  getDistributionIdByLoopId,
  getDistributionCheckLoopVersion
} from '~/api/assetManagement/facilityManagement/loopMonitoringBox'
// import { filterValueEnum } from '~/utils/util'

const loopMonitoringBox: Module<loopMonitoringBoxState, loopMonitoringBoxState> = {
  namespaced: true,
  state: {
    loopConfigureColorList: []
  },
  getters: {
    loopConfigureColorList: (state) => state.loopConfigureColorList
  },
  mutations: {
    SET_LOOP_CONFIGURE_COLOR_LIST(state, payload) {
      state.loopConfigureColorList = payload
    }
  },
  actions: {
    // 查询回路配置颜色数据
    async GetLoopConfigureColors<S, T>({ commit }: ActionContext<S, T>) {
      return await getLoopConfigureColors().then((res: AxiosResponse) => {
        commit('SET_LOOP_CONFIGURE_COLOR_LIST', res?.data?.data || [])
        return res?.data
      })
    },
    // 根据条件查询配电箱回路
    async GetLoopMonitoringBoxList<S, T>(_: ActionContext<S, T>, params: T) {
      return await getLoopMonitoringBoxList<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 根据条件查询配电箱回路（配电设施里的）
    async GetPowerDistributionFacilityCircuit<S, T>(_: ActionContext<S, T>, params: T) {
      return await getPowerDistributionFacilityCircuit<T>(params).then(
        (res: AxiosResponse) => res?.data
      )
    },
    // 根据回路id查询配电id
    async GetDistributionIdByLoopId<S, T>(_: ActionContext<S, T>, params: T) {
      return await getDistributionIdByLoopId<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 检查配电设施的回路版本
    async GetDistributionCheckLoopVersion<S, T>(_: ActionContext<S, T>, params: T) {
      return await getDistributionCheckLoopVersion<T>(params).then(
        (res: AxiosResponse) => res?.data
      )
    }
  }
}

export default loopMonitoringBox
